package de.breitbeil.jbooking.richclient.form.binding;

import java.awt.Color;
import java.util.Calendar;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.UIManager;

import org.jdesktop.swingx.JXDatePicker;
import org.springframework.richclient.application.ApplicationServicesLocator;
import org.springframework.richclient.image.IconSource;

public class JXDatePickerDateFieldBinder extends org.springframework.richclient.form.binding.swing.date.JXDatePickerDateFieldBinder {

    private ImageIcon calendarIcon = null;
    
    public void setIcon(String icon) {
        IconSource iconSource = (IconSource) ApplicationServicesLocator.services().getService(IconSource.class);
        calendarIcon = (ImageIcon) iconSource.getIcon(icon);
    }
    
    protected JComponent createControl(Map context) {
        if(calendarIcon != null) {
            UIManager.put("JXDatePicker.arrowIcon", calendarIcon);
        }
        
        JXDatePicker datePicker = new JXDatePicker();
        
        datePicker.getMonthView().setFirstDayOfWeek(Calendar.MONDAY);
        datePicker.getMonthView().setDayForeground(Calendar.SUNDAY, Color.RED);
        
        return datePicker;
    }
    
}
